package com.qire.manhua.model.vo;

import com.qire.common.basic.StringUtil;
import com.qire.manhua.model.entity.AppInternalAdvert;
import com.qire.manhua.model.enumeration.AdActionType;
import com.qire.manhua.model.viewModel.impl.MainViewModel;
import com.qire.common.support.base.BaseVO;

/**
 * app入场广告信息VO*/
public class AppEnterAdVO extends BaseVO<MainViewModel> {

    public String   ad_title;       //: "满朝王爷一锅端",
    public String   ad_pt;          //: "1",
    public int      ad_type;        //: 0,
    public int      ad_page_type;   //: 1,
    public int      ad_tid;         //: "10210",
    public String   ad_url;         //: "",
    public String   ad_img;         //: "https://p.qiremanhua.com/uploads/default/201807/5b5ade4cbfd53.jpg",
    public String   is_show;        //: "1",
    public int      time;           //: 5

    private AppInternalAdvert toAppInternalAdvert() {
        AdActionType actionType = AdActionType.build(ad_page_type);
        return new AppInternalAdvert(actionType, ad_img, time, ad_tid, ad_title, ad_url);
    }

    @Override
    public void updateModel(MainViewModel viewModel) {
        // 是否显示广告，如果不显示则正常入场
        if(StringUtil.valueToInt(is_show, 0) == 0) {
            viewModel.normalEnter();
            return;
        }
        // 是否显示APP内推广告，如果不显示则显示第三方平台广告
        if(StringUtil.valueToInt(ad_pt, 0) == 1) {
            viewModel.playThirdPartyAD(time);
        } else {
            viewModel.playAppInternalAd(toAppInternalAdvert());
        }
    }
}
